package com.toefl.speaking.handler;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.message.BasicNameValuePair;

import android.content.Context;

import com.toefl.speaking.util.AppConstans;
import com.toefl.speaking.util.AppUtils;

//��֤�Ự
public class RegisterHandler {

	private static RegisterHandler instance;

	private Register register;

	private RegisterHandler() {

	}

	public static RegisterHandler instance() {
		if (instance == null) {
			instance = new RegisterHandler();
		}
		return instance;
	}

	public Register getRegister() {
		if (register == null) {
			register = new Register();
		}
		return register;
	}

	public String postRegister(Register register, Context context)
			throws ClientProtocolException, IOException {
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
		nameValuePairs.add(new BasicNameValuePair(AppConstans.Email, register
				.getEmail()));
		nameValuePairs.add(new BasicNameValuePair(AppConstans.UserName,
				register.getUserName()));
		nameValuePairs.add(new BasicNameValuePair(AppConstans.Passwd, register
				.getPasswd()));
		nameValuePairs.add(new BasicNameValuePair(AppConstans.DeviceToken,
				register.getDeviceToken()));
		return AppUtils.doPost(AppConstans.INTERFACE_URL+"register", nameValuePairs);
	}

	public class Register {
		private String Email;
		private String UserName;
		private String Passwd;
		private String DeviceToken;

		public String getEmail() {
			return Email;
		}

		public void setEmail(String email) {
			Email = email;
		}

		public String getUserName() {
			return UserName;
		}

		public void setUserName(String userName) {
			UserName = userName;
		}

		public String getPasswd() {
			return Passwd;
		}

		public void setPasswd(String passwd) {
			Passwd = passwd;
		}

		public String getDeviceToken() {
			return DeviceToken;
		}

		public void setDeviceToken(String deviceToken) {
			DeviceToken = deviceToken;
		}

	}

}
